package com.gulimall.common.config;

import com.gulimall.common.utils.R;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author by董江
 * @Tool Intellij IDEA
 * @Classname ExceptionHandlerConfig
 * @Date 2022/5/5 23:10
 */
@Log4j2
@RestControllerAdvice
public class ExceptionHandlerConfig {

    @ExceptionHandler(value = RuntimeException.class)
    public R handlerException(RuntimeException exception, HttpServletRequest request){
        String requestURI = request.getRequestURI();
        log.error("在访问路径：{}时产生异常，异常信息：{}",requestURI,exception.getMessage());
        return R.error(exception.getMessage());
    }
}
